home *** CD-ROM | disk | FTP | other *** search
- KEYMAP.COM
- ==========
-
- This is a "quick and dirty" utility I threw together to solve what, for me,
- has been a very iritating problem: lack of a consistent, comprehensive
- C header file for defining keystrokes on an IBM PC.
-
- The idea is simple: define, for each scan code, a set of mnemonic symbols
- which may be used as macro definitions when refering to keys by scan code
- in C programs. To make it even more simple all extended scan codes are
- mapped into the same table by increasing their value by 126 (dec).
-
- This means that for ANY key stroke, a unique code is returned which will
- fit easily into an integer and may be used to identify the key which was
- pressed by means of a simple integer test.
-
- The purpose for this utility is to aid in constructing the keader file by
- actually allowing the user to press each key on the keyboard and assign
- one or more mnemonic names to it. These are then written to a file as
- standard C language #define statements.
-
- This approach makes it easier to be consistent and symetrical in assigning
- names and helps illustrate which keys are, in fact, mapped together. For
- instance CTRL-C and CTRL-BREAK which are the same scan code. It also allows
- the programmer to take advantage of any existing header files s/he may
- already have.
-
- I, of course, used this utility to construct my own header file which I have
- included in this archive. It is called KEYS.H. I also included the source
- code to keymap (keymap.c) which was compiled using Borland Turbo C 2.0. This
- may come in handy for someone who likes the concept but wants to use a
- different key-coding scheme; all you need to do is modify the keyboard
- reading logic to return your scan codes.
-
- Anyway, I hope you find it useful.
-
-
- USING THE PROGRAM
- =================
-
- The program is straight forward but admittedly terse. It insists on two
- arguments: the input file name containing any exisitng define statements and
- the output file name to which the program will write it's definitions when
- it exits.
-
- The input file must be specified and must exist (though it may be empty).
- It may contain zero or more statements of the form:
-
- #define SYMBOL HEXVALUE
-
- for example:
-
- #define ESC_KEY 0x1B
-
- Any lines of a different format except blank lines and lines consisting of
- all whitespace may confuse the program. Sorry, but the values in the
- input file must be in the C language hexidecimal format. If you wish to
- use an existing header file as input to this program and your values are
- not in hex you will need to change the %0X format in the fscanf() call to
- some other format specifier. You may also wish to change the fprintf to
- match though it won't make any difference to your C preprocessor.
-
- These lines are parsed and a table of scan codes is built from them. The
- scan code is the index into the table array and each entry in the table will
- point to a list of zero or more "key names" for that scan code.
-
- The output file need not exist and if it does will be overwritten. The same
- file may be specified for both input and output file. In this case the table
- is read from the file, Definitions are added, and the file is rewritten.
- This is how I use the utility.
-
- If you make a mistake when entering names you may exit the program, fix the
- mistake in the output file using an ASCII text editor, and re-enter the
- program to continue. The program contains no support for directly editing
- or deleting names after they have been entered.
-
- To start the program type:
-
- keymap <infile> <outfile>
-
- and press enter.
-
-
- KEYMAP reads the specified input file and then displays the prompt:
-
- Press a key:
-
- At this point you may depress a single keystroke. The program will determine
- the scan code, display any existing names assigned to it and then display the
- prompt:
-
- #define
-
- enter a mnemonic name for the key (31 characters max) and press <enter>.
-
- The name will be added to the list and another #define prompt will be shown.
- You may enter as many names for the scan code as you wish. When you have
- entered all of them simply press <enter> by itself at the #define prompt and
- you will be taken back to the "Press a key:" prompt.
-
- You may define as many key names as you wish. When you are finished simply
- press the ESCAPE key at the "Press a key:" prompt. The program will write
- the new header file to the output file and return to DOS.
-
- The perceptive reader will observe that it is impossible to map the ESCAPE
- key itself with this program. This is true. You will have to do that
- particular key by hand...sue me!
-
- Beware of pressing CTRL-C or CTRL-BREAK from the "#define" prompt as that
- will cause premature program termination which will result in the loss of
- all definitions added during the current session. It is also likely to be
- embarassing.
-
- This program is not copyrighted, is guaranteed to contain bugs and is not
- supported by the author or anyone else I know of so you're on your own.
- However, any feedback (or just pats on the back) would be well received.
- I can be reached via compuserve c/o:
-
- ORIGIN Technology in Business - 70674,616
-
-
- Hope you enjoy it.
-
- John Hardegree, March 28, 1993.
-